<?php
session_start();
require_once 'bdd.php';
 
$adresse = "";
$mdp = "";

if(isset($_POST['email']))
	$adresse = $_POST['email'];
if (isset($_GET['email'])) 
	$adresse = $_GET['email'];


if(isset($_POST['motdepasse'])){
	$mdp = $_POST['motdepasse'];
}
if (isset($_GET['motdepasse'])){
	$mdp = $_GET['motdepasse'];
}
	

if(isset($adresse) && isset($mdp)) {
	$resultats = $connexion->query("SELECT iduser,mail, prenom, nom, mdp, droit FROM user WHERE mail = ".$connexion->quote($adresse, PDO::PARAM_STR)."
																	  AND mdp =".$connexion->quote($mdp, PDO::PARAM_STR));
	
	$resultats->setFetchMode(PDO::FETCH_OBJ); 
	while( $ligne = $resultats->fetch() ) 
	{
	       $_SESSION['utilisateur'] = $ligne->iduser;
	       $_SESSION['prenomSession'] = $ligne->prenom;
	       $_SESSION['nomSession'] = $ligne->nom;
	       $_SESSION['emailSession'] = $ligne->mail;
		    $_SESSION['droit'] = $ligne->droit;
	       
	}
	$resultats->closeCursor();
}
if(isset($_SESSION['utilisateur'])) {

	$hostAccueil  = $_SERVER['HTTP_HOST'];
	header("Location: http://$hostAccueil");
	
	
} else {
	$host  = $_SERVER['HTTP_HOST'];
	
	header("Location: http://$host");
}

?>
